package library.operation;

import library.BookList;
import library.Book;

import java.util.Scanner;

public class AddOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        //让用户输入新的书籍信息，然后把这个新的书放到booklist中
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = scanner.next();
        System.out.println("请输入作者：");
        String author = scanner.next();
        System.out.println("请输入价格：");
        double price = scanner.nextDouble();
        System.out.println("请输入类型：");
        String type = scanner.next();
        //是否借出，不需要用户输入，默认是未借出
        Book book = new Book(name, author, price, type);

        //把新的书添加到数组的最后一个位置上
        //booklist已经存在n本书籍，
        //这些书对应的下标为0到n-1
        //新增书籍的下标则为n
        //同时size加1
        //此处不考虑书籍列表满的情况
        int size = bookList.getSize();
        bookList.setBook(size, book);
        bookList.setSize(size+1);
        System.out.println("新增图书完成！");
    }
}
